package com.xjf.springboot001.controller;


import com.xjf.springboot001.domain.User;
import com.xjf.springboot001.domain.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
public class UserController {

    @Autowired
    private UserRepository userRepository;

    @RequestMapping("/getUser")
    @Cacheable(value="user-key")
    public User getUser() {
        User user=userRepository.findByUserName("aa4");
        System.out.println("若下面没出现“无缓存的时候调用”字样且能打印出数据表示测试成功");
        return user;
    }

    /**
     *
     * 功能描述:
     *
     * @param:
     * @return:
     * @auther: xujianfeng
     * @date: 2018/10/17 10:01
     *  @Cacheable(value="key-Users") 将com.xjf.springboot001.controller.UserControllergetUser 保存到Redis的zset中
     */
    @RequestMapping("/getUsers")
    @Cacheable(value="key-Users")
    public List<User> getUsers() {
        List<User> users=userRepository.findAll();
        System.out.println("若下面没出现“无缓存的时候调用”字样且能打印出数据表示测试成功");
        return users;
    }
}
